const db = wx.cloud.database();
const _ = db.command;

var appUser = getApp();
Page({
  // 页面的初始数据
  data: {
    user_name: "",
    user_img: "",
    listId: [],
    list: []
  },
  //获取已登录的用户信息
  onShow() {

  },
  onLoad: function () {
    this.data.user_img = appUser.globalData.userImg,
      this.data.user_name = appUser.globalData.userName
    db.collection('user2').where({
      avatarUrl: this.data.user_img,
      nickName: this.data.user_name
    }).get({
      success: res => {
        // console.log(res)
        if (res.data[0].contactBh.length) {
          this.setData({
          listId : res.data[0].contactBh
        })
          // console.log("函数里："+this.data.listId.length);
        }
        // console.log("函数外："+this.data.listId.length)
        for (var i = 0; i < this.data.listId.length; i++) {
          console.log("函数外：" + i)
          this.wait(i)
          //console.log(this.data.list)
        }
      }
    })
  },
  async wait(i) {
    db.collection('beadhouselist').where({
      id: this.data.listId[i]
    }).get().then(res => {
      // console.log("函数里：" + i)
      this.data.list.push(res.data[0])
      // console.log(res.data[i])
      this.setData({
        list: this.data.list
      })
       console.log(this.data.list);
    })
    return;
  }
})